package com.aidex.biz.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.aidex.biz.domain.Customer;
import com.aidex.biz.domain.JinjianInfo;
import com.aidex.biz.domain.bo.IndexBo;
import com.aidex.biz.domain.vo.OrgTypeStatisticVo;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;

import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.JinjianBill;
import com.aidex.biz.service.JinjianBillService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 费用管理Controller
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/biz/bizJinjianBill")
public class JinjianBillController extends BaseController {
    @Autowired
    private JinjianBillService jinjianBillService;

    /**
     * 查询费用管理列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJinjianBill:list')")
    @GetMapping("/list")
    public R<PageInfo> list(JinjianBill jinjianBill, HttpServletRequest request, HttpServletResponse response) {

        jinjianBill.setPage(new PageDomain(request, response));
        return R.data(jinjianBillService.findPage(jinjianBill));
    }

    /**
     * 获取费用管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJinjianBill:query')")
    @GetMapping(value = "/{id}")
    public R<JinjianBill> detail(@PathVariable("id") String id) {
        return R.data(jinjianBillService.get(id));
    }

    /**
     * 新增费用管理
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJinjianBill:add')")
    @Log(title = "费用管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated JinjianBill jinjianBill) {
        return R.status(jinjianBillService.save(jinjianBill));
    }

    /**
     * 修改费用管理
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJinjianBill:edit')")
    @Log(title = "费用管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated JinjianBill jinjianBill) {
        if (jinjianBill.getCaiwuCheck().equals("1") && null == jinjianBill.getCheckTime()) {
            jinjianBill.setCheckTime(new Date());
        }
        return R.status(jinjianBillService.save(jinjianBill));
    }


    /**
     * 删除费用管理
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJinjianBill:remove')")
    @Log(title = "费用管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(jinjianBillService.deleteJinjianBillByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJinjianBill:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort() {
        return R.data(jinjianBillService.findMaxSort(new JinjianBill()));
    }

    /**
     * 导出费用管理列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJinjianBill:export')")
    @Log(title = "费用管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(JinjianBill jinjianBill) {

        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            jinjianBill.setCompanyId(null);
        } else {
            jinjianBill.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        List<JinjianBill> list = jinjianBillService.findList(jinjianBill);
        ExcelUtil<JinjianBill> util = new ExcelUtil<JinjianBill>(JinjianBill.class);
        return util.exportExcel(list, "费用管理数据");
    }

    /**
     * 费用统计
     *
     * @param jinjianBill
     * @return
     */
    @Log(title = "费用统计", businessType = BusinessType.SELECT)
    @GetMapping("/orgTypeStatistic")
    public R<PageInfo> orgTypeStatistic(JinjianBill jinjianBill, HttpServletRequest request, HttpServletResponse response) {
        jinjianBill.setPage(new PageDomain(request, response));
        return R.data(jinjianBillService.orgTypeStatistic(jinjianBill));
    }

    /**
     * 费用统计 合计
     *
     * @param jinjianBill
     * @return
     */
    @Log(title = "费用统计(合计)", businessType = BusinessType.SELECT)
    @GetMapping("/sumOrgTypeStatistic")
    public R sumOrgTypeStatistic(JinjianBill jinjianBill, HttpServletRequest request, HttpServletResponse response) {
        jinjianBill.setPage(new PageDomain(request, response));
        return R.data(jinjianBillService.sumOrgTypeStatistic(jinjianBill));
    }

    /**
     * 个人统计
     *
     * @param jinjianBill
     * @return
     */
    @Log(title = "个人统计", businessType = BusinessType.SELECT)
    @GetMapping("/oneSelfStatistic")
    public R<PageInfo> oneSelfStatistic(JinjianBill jinjianBill, HttpServletRequest request, HttpServletResponse response) {
        jinjianBill.setPage(new PageDomain(request, response));
        return R.data(jinjianBillService.oneSelfStatistic(jinjianBill));
    }


    /**
     * 个人统计上部总计
     *
     * @param jinjianBill
     * @return
     */
    @Log(title = "个人统计上部总计", businessType = BusinessType.SELECT)
    @GetMapping("/oneSelfZongStatistic")
    public R oneSelfZongStatistic(JinjianBill jinjianBill, HttpServletRequest request,
                                  HttpServletResponse response) {
        jinjianBill.setPage(new PageDomain(request, response));
        return R.data(jinjianBillService.oneSelfZongStatistic(jinjianBill));
    }


    @Log(title = "费用统计", businessType = BusinessType.EXPORT)
    @GetMapping("/exportOrgTypeStatistic")
    public R exportOrgTypeStatistic(JinjianBill jinjianBill) {
        List<OrgTypeStatisticVo> list = jinjianBillService.ExportOrgTypeStatistic(jinjianBill);
        ExcelUtil<OrgTypeStatisticVo> util = new ExcelUtil<OrgTypeStatisticVo>(OrgTypeStatisticVo.class);
        return util.exportExcel(list, "费用统计");
    }


    /**
     * 首页统计 数据简报
     *
     * @param
     * @return
     */
    @Log(title = "首页统计 数据简报", businessType = BusinessType.SELECT)
    @GetMapping("/indexDataJianBao")
    public R indexDataJianBao(IndexBo indexBo) {
        return R.data(jinjianBillService.indexDataShow(indexBo));
    }


    /**
     * 首页统计 个人排行榜
     *
     * @param indexBo
     * @return
     */
    @Log(title = "首页统计 数据简报", businessType = BusinessType.SELECT)
    @GetMapping("/indexPaiHangBangSelf")
    public R indexPaiHangBangSelf(IndexBo indexBo) {
        return R.data(jinjianBillService.indexPaiHangBangSelf(indexBo));
    }


    /**
     * 首页统计 部门排行榜
     *
     * @param indexBo
     * @return
     */
    @Log(title = "首页统计 数据简报", businessType = BusinessType.SELECT)
    @GetMapping("/indexPaiHangBangDept")
    public R indexPaiHangBangDept(IndexBo indexBo) {
        return R.data(jinjianBillService.indexPaiHangBangDept(indexBo));
    }

    /**
     * 首页快捷操作 待完成
     *
     * @param indexBo
     * @return
     */
    @Log(title = "首页快捷操作 待完成", businessType = BusinessType.SELECT)
    @GetMapping("/indexDaiCaoZuo")
    public R indexDaiCaoZuo(IndexBo indexBo) {
        indexBo.setUserId(SecurityUtils.getUserId());
        return R.data(jinjianBillService.indexDaiCaoZuo(indexBo));
    }


    /**
     * 广告进线分析
     *
     * @param
     * @return
     */
    @Log(title = "广告进线分析", businessType = BusinessType.SELECT)
    @GetMapping("/xiansuofenxi")
    public R xiansuofenxi(Customer customer) {
        return R.data(jinjianBillService.xiansuofenxi(customer));
    }


    @Log(title = "财务确认", businessType = BusinessType.UPDATE)
    @PostMapping("/bizJinjianBillCaiWuConfirm")
    public R bizJinjianBillCaiWuConfirm(@RequestBody JinjianBill jinjianBill) {
        return R.status(jinjianBillService.bizJinjianBillCaiWuConfirm(jinjianBill));
    }
}
